define(
		[ "PDAppDir/properties", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar",
				"PDUtilDir/inputSelect",
				"PDUtilDir/fileupload/singleFileUpload", "Date", "DateCN",
				"css!DateCss" ],
		function(Properties, Util, Tool, Slidebar, inputSelect, MFU) {
			function paySupportInit($scope, $compile) {
				return new paySupport($scope, $compile);
			}
			function paySupport($scope, $compile) {
				this.$scope = $scope;
				this.$compile = $compile;
				
				this.cache = $.extend({
					fileServer: Properties.URL_FILE_SERVER_URL
				}, this.$scope.cache);
				
				this.bind = {}
			}
			paySupport.fn = paySupport.prototype;
			paySupport.fn.digest = function() {
				this.$scope.$digest();
			}
			paySupport.fn.init = function(id) {
				var _this = this;
			    $.ajax({
					url : getServer() + "/flea/hclv/serviceOrder/findDetailById.htmls",
					data: {
				    	model : id,
				    },
					success : function(data) {
						if(data.status != 200){
							return
						}
						_this.entity = $.extend({
							pays: new Array()
						},data.data);
						_this.entity.orderStatusName = _this.$scope.cache.orderStatusMap.get(_this.entity.order.payStatus);

                        $.ajax({
                            url : getServer() + "/flea/hclv/qr/manage/selectByGDeptId.htmls",
							data: {
                                deptId: _this.entity.order.supplerOrgId
							},
                            success : function(data) {
                                if(data.status != 200){
                                    return
                                }
                                _this.cache.images = data.data;
                                _this.digest();
                            }
                        });
					}
				});
			};
			paySupport.fn.run = function(data) {
				var _this = this;
				_this.init(data);
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/order/buyOrderInfos/views/pay.html",
//					close : true,
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			paySupport.fn.initialization = function() {
				var _this = this;
				// 初始化支付类型下拉框
				inputSelect.dropCache();
				inputSelect({
					id : "payPlatformName",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.$scope.cache.types,
					simpleData : true,
					searchAble : false,
					callback : function(id, obj) {
						_this.bind.payPlatform = id[0];
						_this.bind.payPlatformName = obj[0].dictName;
						_this.$scope.payServiceOrderForm.payPlatform.$setViewValue(_this.bind.payPlatform);
					}
				});
//				_this.$scope.$watch("paySupport.entity.pays", function(values){
//					console.info(values);
//				});
				
//				_this.cache.images = [{
//					type: "D_PAY_TYPE_WECHAT",
//					qrCodePath: "http://www.baidu.com/a.png"
//				},{
//					type: "D_PAY_TYPE_ALIPAY",
//					qrCodePath: "http://www.baidu.com/b.png"
//				}];
			};
			paySupport.fn.add = function() {
				this.entity.pays.push($.extend({},this.bind));
				this.bind = {
					payPlatform: this.bind.payPlatform,
					payPlatformName:  this.bind.payPlatformName
				};
				this.cache.isOk = true;
				this.$scope.payServiceOrderSaveForm.pays.$setViewValue(this.cache.isOk);
				this.$scope.payServiceOrderForm.payPlatform.$setViewValue(this.bind.payPlatform);
			};
			paySupport.fn.save = function() {
				var _this = this;
				$.ajax({
					url : getServer() + "/flea/hclv/serviceOrder/addPay.htmls",
					data : {
						'model' : JSON.stringify({
							orderNo : _this.entity.order.orderNo,
							payItems: _this.entity.pays
						})
					},
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.$scope.grid.refresh();
						Util.alert(data.message);
						_this.slidebars.close();
					}
				});
			};
			return paySupportInit;
		});